<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html >
<html>
<head>
<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
<style type="text/css">
.panel-title a{display: block;}
</style>
</head>
<body style="background-color: white;" class="gray-bg">
	<div class="ibox-content">
		<form class="form-horizontal m-t " id="signupForm"
			method="post" enctype="multipart/form-data">
			<input type="hidden" name="id"  id="id" value="${id }">
			<div class="panel-group" id="accordion">
				<div class="panel panel-default">
					<div class="panel-heading">
						<h4 class="panel-title">
							<a data-toggle="collapse" data-parent="#accordion"
								href="#collapseOne"> 基本信息 </a>
						</h4>
					</div>
					<div id="collapseOne" class="panel-collapse collapse in">
						<div class="panel-body ">
						<div class="form-group">
								<label class="col-sm-3 control-label">选择文件：</label>
								<div class="col-sm-5">
									<input type="file" style="width: 50%" id="file"/>
								</div>
								<div class="col-sm-3"><button type="button" class="btn btn-info" onclick="Analysis();">解析</button></div>
							</div>
							<div class="form-group">
								<!-- Select Basic -->
								<label class="col-sm-3 control-label">类型：</label>
								<div class="col-sm-8">
									<select class="form-control" name="type">
									<c:forEach items="${fns:getDictList('resume_type')}" var="temp1">
										<option value="${temp1.value }">${temp1.valueName }</option>
									 </c:forEach>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">行业：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="industryName" onclick="openTree('industry');" placeholder="请选择行业" readonly="readonly"/>
				                    <input type="hidden" name="industryId" id="industryId"/>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">姓名：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="name" name="name" />
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">性别：</label>
								<div class="col-sm-8">
									<label class="radio-inline"> <input value="1"
										checked="checked" name="sex" type="radio"> 男
									</label> <label class="radio-inline"> <input value="2"
										name="sex" type="radio"> 女
									</label>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">国籍：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="nationality"
										name="nationality" value="${resume.name }"/>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">出生日期：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control datetime" id="birthdate"
										name="birthdate" readonly="readonly" placeholder="请选择日期" value="${resume.name }"/>
								</div>
							</div>
							<div class="form-group">
								<!-- Select Basic -->
								<label class="col-sm-3 control-label">婚姻状况</label>
								<div class="col-sm-8">
									<select class="form-control" name="conditions">
									<c:forEach items="${fns:getDictList('resume_conditions')}" var="temp">
										<option value="${temp.value }">${temp.valueName }</option>
									 </c:forEach>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">学历：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="education"
										name="education" value="${resume.education }"/>
								</div>
							</div>
							<div class="form-group">
								<!-- Select Basic -->
								<label class="col-sm-3 control-label">目前薪酬</label>
								<div class="col-sm-8">
								<input type="text" class="form-control" id="emolument"
										name="emolument" />
								</div>
							</div>
							<div class="form-group">
								<!-- Select Basic -->
								<label class="col-sm-3 control-label">是否看机会</label>
								<div class="col-sm-8">
									<label class="radio-inline"> <input value="1"
										checked="checked" name="ischance" type="radio"> 是
									</label> <label class="radio-inline"> <input value="2"
										name="ischance" type="radio"> 否
									</label>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">目前所在城市：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="areaName"  placeholder="请选择区域" readonly="readonly" onclick="openTree('area')"/>
					                <input type="hidden" class="form-control" id="areaId" name="location" />
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">期望工作城市：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="area1Name"  placeholder="请选择区域" readonly="readonly" onclick="openTree('area',1)"/>
					                <input type="hidden" class="form-control" id="area1Id" name="expectedCity" />
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">邮箱：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="email" name="email" value="${resume.email }"/>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">手机号码：</label>
								<div class="col-sm-6">
									<input type="text" class="form-control" id="cellphone" name="cellphone" placeholder="请点击增加" readonly="readonly" value="${resume.cellphone }"/>
								    <input type="hidden" class="form-control" id="cellphoneids" name="phoneIds"/>
								</div>
								<div class="col-sm-2"><button type="button" class="btn btn-info" onclick="addPhone();">增加</button></div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">QQ：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="qq" name="qq" />
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">微信：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="wechat"
										name="wechat" />
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">标签：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="tagName" name="tag" placeholder="请选择标签" readonly="readonly" onclick="openTree('tag')"/>
					                <input type="hidden" class="form-control" id="tagId" name="tagIds" />
								</div>
							</div>
							<div id="menuContent" class="menuContent" style="display:none; position: absolute;">
								<ul id="treeDemo" class="ztree" style="margin-top:0; width:180px; height: 300px;"></ul>
							</div>
						</div>
					</div>
				</div>
				<div class="panel panel-success">
					<div class="panel-heading">
						<h4 class="panel-title">
							<a data-toggle="collapse" data-parent="#accordion"
								href="#collapseTwo"> 工作经历 </a>
						</h4>
					</div>
					<div id="collapseTwo" class="panel-collapse collapse">
						<div class="panel-body">
						<div class="form-group">
								<label class="col-sm-3 control-label">起止时间：</label>
								<div class="col-sm-8 form-inline">
									<input type="text" class="form-control datetime" id="w_startDate" name="workExp.startDate"  style="width: 40%" readonly="readonly" placeholder="请选择日期"/> -
									<input type="text" class="form-control datetime" id="w_endDate" name="workExp.endDate"  style="width: 40%" readonly="readonly" placeholder="请选择日期"/>
								</div>
							</div>
						  <div class="form-group">
								<label class="col-sm-3 control-label">公司名称：</label>
								<div class="col-sm-6">
									<select id="w_companyId" name="workExp.companyId" data-placeholder="选择公司"
										class="form-control selectpicker bla bla bli"  data-live-search="true"  onclick="choosewCompany();">
									</select>
								</div>
								<div class="col-sm-2"><button type="button" class="btn btn-info" onclick="addwCompany();">增加</button></div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">职位名称：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="w_position" name="workExp.position" />
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">部门名称：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="w_depId" name="workExp.depId" />
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">汇报上级：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="w_report" name="workExp.report" />
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">下属人数：</label>
								<div class="col-sm-8">
									<input type="number" class="form-control" id="w_subordinateNum" name="workExp.subordinateNum" />
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">工作职责：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="w_responsibility" name="workExp.responsibility" />
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">工作业绩：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="t_performance" name="workExp.performance" />
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">项目经验：</label>
								<div class="col-sm-8">
									<textarea rows="3" cols="3" class="form-control" id="t_project" name="workExp.project" ></textarea>
								</div>
							</div>
							<div class="form-group" style="text-align: center;">
								<div class="col-sm-12">
									<button type="button" class="btn btn-primary btn-sm addbtn"><i class="fa fa-plus"></i></button>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="panel panel-info">
					<div class="panel-heading">
						<h4 class="panel-title">
							<a data-toggle="collapse" data-parent="#accordion"
								href="#collapseThree"> 教育经历 </a>
						</h4>
					</div>
					<div id="collapseThree" class="panel-collapse collapse">
						<div class="panel-body">
						<div class="form-group">
								<label class="col-sm-3 control-label">起止时间：</label>
								<div class="col-sm-8 form-inline">
									<input type="text" class="form-control datetime" id="e_startDate" name="eduExp.startDate"  style="width: 40%" readonly="readonly" placeholder="请选择起始时间"/> -
									<input type="text" class="form-control datetime" id="e_endDate" name="eduExp.endDate"  style="width: 40%" readonly="readonly" placeholder="请选择截止时间"/>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">学校名称：</label>
								<div class="col-sm-6">
									<select id="e_schoolId" name="eduExp.schoolId" data-placeholder="选择学校"
										class="form-control selectpicker bla bla bli"  data-live-search="true"  required="required">
									</select>
								</div>
								<div class="col-sm-2"><button type="button" class="btn btn-info" onclick="addSchool(1);">增加</button></div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">专业：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="e_profession" name="eduExp.profession" />
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">学历：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="e_education" name="eduExp.education" />
								</div>
							</div>
							<div class="form-group" style="text-align: center;">
								<div class="col-sm-12">
									<button type="button" class="btn btn-primary btn-sm addbtn"><i class="fa fa-plus"></i></button>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="panel panel-warning">
					<div class="panel-heading">
						<h4 class="panel-title">
							<a data-toggle="collapse" data-parent="#accordion"
								href="#collapseFour"> 培训经历 </a>
						</h4>
					</div>
					<div id="collapseFour" class="panel-collapse collapse">
						<div class="panel-body">
						<div class="form-group">
								<label class="col-sm-3 control-label">起止时间：</label>
								<div class="col-sm-8 form-inline">
									<input type="text" class="form-control datetime" id="t_startDate" name="trainExp.startDate"  style="width: 40%" readonly="readonly" placeholder="请选择起始时间"/> -
									<input type="text" class="form-control datetime" id="t_endDate" name="trainExp.endDate"  style="width: 40%" readonly="readonly" placeholder="请选择截止时间"/>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">培训机构：</label>
								<div class="col-sm-6">
									<select id="t_schoolId" name="trainExp.schoolId" data-placeholder="选择培训机构"
										class="form-control selectpicker bla bla bli"  data-live-search="true"  required="required">
									</select>
								</div>
								<div class="col-sm-2"><button type="button" class="btn btn-info" onclick="addSchool(2);">增加</button></div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">培训课程：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="t_course" name="trainExp.course" />
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">取得成绩：</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="t_grade" name="trainExp.grade" />
								</div>
							</div>
							<div class="form-group" style="text-align: center;">
								<div class="col-sm-12">
									<button type="button" class="btn btn-primary btn-sm addbtn"><i class="fa fa-plus"></i></button>
								</div>
							</div>
						</div>
					</div>
						</div>
					</div>
				</div>
			</div>

			<div class="form-group" style="text-align: center;">
				<div class="col-sm-12">
					<button class="btn btn-primary" type="button" id="sub">提交</button>
				</div>
			</div>
		</form>
	</div>


	<script>
	$(".datetime").datetimepicker({//选择年月日
			format: 'yyyy-mm-dd',
			language: 'zh-CN',
			weekStart: 1,
			todayBtn: 1,//显示‘今日’按钮
			autoclose: 1,
			todayHighlight: 1,
			startView: 2,
			minView: 2,  //Number, String. 默认值：0, 'hour'，日期时间选择器所能够提供的最精确的时间选择视图。
			clearBtn:true,//清除按钮
			forceParse: 0
	});
    $(function () {
    	chooseSchool(1);
    	chooseSchool(2);
        var temp = 2; 
        $(".addbtn").click(function(){
   	　　　　var copy_str=$(this).parents(".panel-body").clone();
   	　　　　copy_str.find("i").removeClass("fa-plus").addClass("fa-minus");
   	　　　　copy_str.find("button").removeClass("addbtn");
      	         copy_str.find("[id]").each(function(){
      	        	 var id = $(this).attr("id");
      	        	$(this).attr("id",id+temp); 
      	        	$(this).attr("name",id+temp); 
      	         })
   	　　　　copy_str.find(".col-sm-12 button").attr("onclick","canelf(this)");
      	         copy_str.find(".col-sm-2 button").hide();
   	　　　　$(this).parent().parent().parent().before(copy_str);
   	    temp +=1;
        });
        $("#sub").click(function () {
        	//批量验证表单非空
        	function checkForm(arr){
        	  for(var i=0;i<arr.length;i++){
	        	  if($("#"+arr[i][0]).val()==''){
	        		  $("#"+arr[i][0]).tips({
	  					side:3,
	  		            msg:arr[i][1],
	  		            bg:'#AE81FF',
	  		            time:1
	  		        });
	        		  $("#"+arr[i][0]).focus();
	  				return;
	  			}
        	  }
        	  return true;
        	};
        	//调用方式
        	var arr=new Array(
        	  new Array('type','类型未选择!'),
        	  new Array('industryName','行业未选择!'),
        	  new Array('name','姓名未填写!'),
        	  new Array('industryName','公司行业未选择!'),
        	  new Array('education','学历未填写!'),
        	  new Array('areaName','目前所在地未选择!')
        	);
        	if(!checkForm(arr)){
        	  return false;
        	}
            $("#signupForm").ajaxSubmit({
                url: '<%=contextPath%>/resume/add',
                    data:{num:temp},
					type : 'post',
					dataType : "json",
					success : function(data) {
						if (data.code == 200) {
							swal({
								title : data.message,
								type : "success",
								showCancelButton : false,
								confirmButtonText : "确定",
								animation : "slide-from-bottom",
								closeOnConfirm : true
							}, function() {
								top.Dialog.close();
							});
						} else {
							swal("错误", data.message, "error");
						}
					}
				});
			});
		});
    function canelf(e){
        $(e).parent().parent().parent().remove();
   	}
    function choosewCompany(){
      	$.ajax({
      		url:'<%=contextPath%>/company/getJson',
      	    type:'post',
      	    dataType:'json',
      	    success:function(data){
      	    	var html='<option  value="">==请选择==</option>';
      	    	for (var i = 0; i < data.length; i++) {
      	    		html+='<option  value="'+data[i].id+'">'+data[i].name+'</option>';
					}
      	    	$("#w_companyId").html(html);
      	    	$("#w_companyId").selectpicker('refresh');
      	    }
      	});
      }
    function chooseSchool(type){
      	$.ajax({
      		url:'<%=contextPath%>/school/getJson',
      		data:{type:type},
      	    type:'post',
      	    dataType:'json',
      	    cache:true,
      	    success:function(data){
      	    	var htmle='<option  value="">==请选择==</option>';
      	    	var htmlt='<option  value="">==请选择==</option>';
      	    	for (var i = 0; i < data.length; i++) {
      	    		htmle+='<option  value="'+data[i].id+'">'+data[i].name+'</option>';
      	    		htmlt+='<option  value="'+data[i].id+'">'+data[i].name+'</option>';
					}
      	    	if(type==1){
          	    	$("#e_schoolId").html(htmle);
          	    	$("#e_schoolId").selectpicker('refresh');
      	    	}
      	    	if(type==2){
          	    	$("#t_schoolId").html(htmlt);
          	    	$("#t_schoolId").selectpicker('refresh');
      	    	}
      	    }
      	});
      }
    //分配资源
	function openTree(obj,num){
	     var ids = $("#"+obj+"Id").val();
	   	 var diag = new top.Dialog();
		 diag.Drag=true;
		 diag.Title ="请选择";
		 diag.URL = '<%=contextPath %>/'+obj+'/openZtree?ids='+ids;
		 diag.Width = 250;
		 diag.Height = 400;
		 diag.CancelEvent = function(){ //关闭事件
			 var tempid = diag.innerFrame.contentWindow.document.getElementById('tempids').value;
			 var tempname = diag.innerFrame.contentWindow.document.getElementById('tempnames').value;
			if(tempid.length!==0){
				if(typeof(num)=="undefined"){ 
					$("#"+obj+"Id").val(tempid);
					$("#"+obj+"Name").val(tempname);
				}else{
					$("#"+obj+num+"Id").val(tempid);
					$("#"+obj+num+"Name").val(tempname);
				}
			}
			diag.close();
		 };
		 diag.show();
	}
    function addPhone() {
    	 var talentsid =$("#id").val();
    	 var diag = new top.Dialog();
		 diag.Drag=true;
		 diag.Title ="请选择";
		 diag.URL = '<%=contextPath %>/cellphone/addphone?talentid='+talentsid;
		 diag.Width = 350;
		 diag.Height = 350;
		 diag.CancelEvent = function(){ //关闭事件
			 var phoneids = diag.innerFrame.contentWindow.document.getElementById('phoneids').value;
			 var phoneName = diag.innerFrame.contentWindow.document.getElementById('phoneName').value;
			 var phonenum;
			 var phoneidnum;
			if(phoneids.length!==0){
				if($.trim($("#cellphone").val()).length ==0){
					phonenum = phoneName;
					phoneidnum =phoneids;
				}else {
					phonenum = $("#cellphone").val()+","+phoneName;
					phoneidnum = $("#cellphoneids").val()+","+phoneids;
				}
				$("#cellphone").val(phonenum);
				$("#cellphoneids").val(phoneidnum);
			}
			diag.close();
		 };
		 diag.show();
    	 
	}
    function addwCompany(){
    	openyem("添加公司", "<%=contextPath%>/company/addView", 550, 550);
    	choosewCompany();
    }
    function addSchool(obj){
    	if(obj ==1){
    		openyem("添加学校", "<%=contextPath%>/school/addView?type="+obj, 550, 550);
    	}
    	if(obj ==2){
    		openyem("添加机构", "<%=contextPath%>/school/addView?type="+obj, 550, 550);
    	}
    	
    }
    function Analysis() {
    	var fileObj = document.getElementById("file").files[0]; // js 获取文件对象
        if (typeof (fileObj) == "undefined" || fileObj.size <= 0) {
            //alert("请选择文件");
            return;
        }
        var formFile = new FormData();
        formFile.append("action", "UploadVMKImagePath");  
        formFile.append("file", fileObj); //加入文件对象
        var data = formFile;
        $.ajax({
            url: "<%=contextPath%>/resume/upload",
            data: data,
            type: "post",
            dataType: "json",
            cache: false,//上传文件无需缓存
            processData: false,//用于对data参数进行序列化处理 这里必须false
            contentType: false, //必须
            success: function (result) {
            	
            	if(result.code ==200){
                    alert("解析完成!");
                    $("#name").val(result.datas.name);
                    $("#birthdate").val(result.datas.birthdate);
                    $("#cellphone").val(result.datas.cellphone);
                    $("#nationality").val(result.datas.nationality);
                    $("#email").val(result.datas.email);
                    $("#education").val(result.datas.education);
            	}
            },
        }) 
	}
	</script>
</body>
</html>